package com.jinxiangyang.service.impl;

import com.jinxiangyang.domain.vo.*;
import com.jinxiangyang.mapper.CourseMapper;
import com.jinxiangyang.mapper.OrderInfoMapper;
import com.jinxiangyang.mapper.UserInfoMapper;
import com.jinxiangyang.service.ChartsService;
import com.jinxiangyang.utils.context.ProvinceLal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class ChartsServiceImpl implements ChartsService {

    @Autowired
    UserInfoMapper userInfoMapper;

    @Autowired
    CourseMapper courseMapper;

    @Autowired
    OrderInfoMapper orderInfoMapper;

    @Override
    public List<UserTypeAmountVo> getUserTypePercent() {
        List<UserTypeAmountVo> userType = userInfoMapper.getUserType();
        for (UserTypeAmountVo userTypeAmountVo : userType) {
            String type = userTypeAmountVo.getName();
            if ("1".equals(type)) {
                userTypeAmountVo.setName("中级用户");
            } else if ("2".equals(type)) {
                userTypeAmountVo.setName("高级用户");
            } else if ("3".equals(type)) {
                userTypeAmountVo.setName("至上用户");
            } else if ("4".equals(type)) {
                userTypeAmountVo.setName("尊贵用户");
            } else if ("5".equals(type)) {
                userTypeAmountVo.setName("黑卡用户");
            } else {
                userTypeAmountVo.setName("普通用户");
            }
        }
        return userType;
    }

    @Override
    public List<UserMapVo> getUserMap() {
        List<UserMapVo> userMapVoList = userInfoMapper.getUserMap();
        for (UserMapVo userMapVo : userMapVoList) {
            String province = userMapVo.getName();
            double[] doubles = ProvinceLal.tranLal(province);
            userMapVo.setValue(doubles);
        }
        return userMapVoList;
    }

    @Override
    public List<CourseTypeAccountVo> getCourseTypePercent() {
        List<CourseTypeAccountVo> courseTypePercent = courseMapper.getCourseTypePercent();
        return courseTypePercent;
    }

    @Override
    public int[] getCourseSale() {
        List<CourseSaleVo> courseSaleVoList = orderInfoMapper.getCourseSale();
        int[] values = new int[12];
        if(courseSaleVoList.size()>0&& courseSaleVoList!=null){
            for (int i = 0; i < courseSaleVoList.size(); i++) {
                CourseSaleVo courseSaleVo = courseSaleVoList.get(i);
                if(courseSaleVo.getName()!=null){
                    Integer month = this.getMonth(courseSaleVo.getName());
                    values[month-1]=courseSaleVo.getValue();
                }
            }
        }

        return values;
    }

    @Override
    public double[] getCourseSales() {
        List<CourseSalesVo> courseSalesVoList = orderInfoMapper.getCourseSales();
        double[] values = new double[12];
        if(courseSalesVoList.size()>0&& courseSalesVoList!=null) {
            for (int i = 0; i < courseSalesVoList.size(); i++) {
                CourseSalesVo courseSalesVo = courseSalesVoList.get(i);
                if (courseSalesVo.getName() != null) {
                    Integer month = this.getMonth(courseSalesVo.getName());
                    values[month - 1] = courseSalesVo.getValue();
                }
            }
        }
        return values;
    }




    private Integer getMonth(String month){
        return Integer.valueOf(month);
    }


}
